﻿<?php
/**
 * Created by PhpStorm.
 * User: diandong.cao
 * Date: 15-3-17
 * Time: 下午2:19
 */

class wx{

    /**
     * 使用code换取access_token
     * Enter description here ...
     * @param appid公众号的唯一标识z
     * @param appsecret秘钥
     */
    function getAccess_token($appid,$appsecret){
        $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$appsecret."&code=".$_GET['code']."&grant_type=authorization_code";
        $result = file_get_contents($url);
        $result = json_decode($result,true);
        return $result;
    }



    /*
     * 获得用户信息
     * Enter description here ...
     * @param $access_token
     * @param $openid
     */
    function getUserInfo($access_token,$openid){
        $url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_CN";
        $user = file_get_contents($url);
        $user = json_decode($user,true);
        return $user;
    }

}
